<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Carbon;

class SeckillListResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'name'          => $this->name,
            'start_at'      => strtotime($this->start_at),
            'end_at'        => strtotime($this->end_at),
            'date_time_name' => now()->gt($this->start_at) ? '正在抢购' : Carbon::parse($this->start_at)->format('m月d H:i'),
            'product'       => ProductListResource::collection($this->whenLoaded('product'))
        ];
    }
}
